﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AgileTimeTracker.Client.Wpf.Common;
using AgileTimeTracker.Domain.TaskModule;
using Cwi.Utils;

namespace AgileTimeTracker.Client.Wpf.TimeControlModule
{
    public class TaskWorkTimeItemViewModel : BaseViewModel
    {
        #region Fields

        private string userStory;
        private string iterationPath;
        private double completedWork;
        private double estimatedWork;
        private double remainingWork;
        private double totalWorkTime;
        private double totalWorkTimeToday;
        private int? tfsWorkItemId;

        private TfsTask tfsTask;

        #endregion // Fields

        public TaskWorkTimeItemViewModel(TfsTask tfsTask)
        {
            this.Refresh(tfsTask);
        }

        #region Properties

        public TfsTask CurrentTask
        {
            get { return this.tfsTask; }
        }

        public double TotalWorkTime
        {
            get { return this.totalWorkTime; }
            set { this.OnPropertyChanged(ref this.totalWorkTime, value); }
        }

        public double TotalWorkTimeToday
        {
            get { return this.totalWorkTimeToday; }
            set { this.OnPropertyChanged(ref this.totalWorkTimeToday, value); }
        }

        public string UserStory
        {
            get { return this.userStory; }
            set { this.OnPropertyChanged(ref this.userStory, value); }
        }

        public string IterationPath
        {
            get { return this.iterationPath; }
            set { this.OnPropertyChanged(ref this.iterationPath, value); }
        }

        public double CompletedWork
        {
            get { return this.completedWork; }
            set { this.OnPropertyChanged(ref this.completedWork, value); }
        }

        public double EstimatedWork
        {
            get { return this.estimatedWork; }
            set { this.OnPropertyChanged(ref this.estimatedWork, value); }
        }

        public double RemainingWork
        {
            get { return this.remainingWork; }
            set { this.OnPropertyChanged(ref this.remainingWork, value); }
        }

        public int? TfsWorkItemId
        {
            get { return this.tfsWorkItemId; }
            set { this.OnPropertyChanged(ref this.tfsWorkItemId, value); }
        }

        #endregion // Properties

        #region Initialize

        public void Refresh(TfsTask tfsTask = null)
        {
            if (tfsTask == null && this.tfsTask == null)
            {
                throw new ArgumentNullException("tfsTask");
            }

            if (tfsTask != null)
            {
                this.tfsTask = tfsTask;
            }            

            this.Title = this.tfsTask.Title;
            this.UserStory = this.tfsTask.UserStory;
            this.IterationPath = this.tfsTask.IterationPath;
            this.CompletedWork = this.tfsTask.CompletedWork;
            this.RemainingWork = this.tfsTask.RemainingWork;
            this.EstimatedWork = this.tfsTask.EstimatedWork;
            this.TfsWorkItemId = this.tfsTask.TfsWorkItemId;
            this.TotalWorkTime = this.tfsTask.TotalWorkTime;
            this.TotalWorkTimeToday = this.tfsTask.TotalWorkTimeToday;
        }

        #endregion // Initialize
    }
}
